//
//  TuanTableViewCell.m
//  Findif
//
//  Created by Mac on 2018/11/22.
//  Copyright © 2018年 Cicel Chen. All rights reserved.
//

#import "TuanTableViewCell.h"

@interface TuanTableViewCell ()

@property (nonatomic, weak)UILabel * timeLabel;
@property (nonatomic, weak)UILabel * peopleLabel;
@property (nonatomic, weak)UILabel * stopLabel;


@end

@implementation TuanTableViewCell


-(void)setModel:(ShowTuanWeek *)model{
    
    _model = model;
    
    self.timeLabel.text = [NSString stringWithFormat:@"%@场",model.time];
//    self.peopleLabel.text = [NSString stringWithFormat:@"还差%@人满员",model.poor_number];
    self.stopLabel.text = [NSString stringWithFormat:@"截止时间:%@",model.end_group_time];
}

- (void)setDict:(NSDictionary *)dict{
    
    _dict = dict;
    
    int merchants_goods_max_pople = [dict[@"merchants_goods_max_pople"] intValue];
    int merchants_goods_min_pople = [dict[@"merchants_goods_min_pople"] intValue];
    int buyNum = [self.model.buy_number intValue];
    
    if (buyNum >= merchants_goods_min_pople) {
        
        int res = merchants_goods_max_pople - buyNum;
        self.peopleLabel.text = [NSString stringWithFormat:@"还差%d人满员",res];
    }else{
        
        int res = merchants_goods_min_pople - buyNum;
        self.peopleLabel.text = [NSString stringWithFormat:@"还差%d人拼团成功",res];
    }
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
    }
    
    return self;
}

- (void)setupUI{
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.backgroundColor = ColorWithRGB(0xF4F5F6);
    
    UILabel * timeLabel = [UILabel new];
    
    timeLabel.textColor = ZRBlackColor;
    timeLabel.font = [UIFont systemFontOfSize:15 * SCREENH6];
    timeLabel.text = @"11:00场";
    
    self.timeLabel = timeLabel;
    
    [self.contentView addSubview:self.timeLabel];
    
    UILabel * peopleLabel = [UILabel new];
    
    peopleLabel.textColor = ZRBlackColor;
    peopleLabel.font = [UIFont systemFontOfSize:13 * SCREENH6];
    peopleLabel.text = @"还差11人拼团成功";
    
    self.peopleLabel = peopleLabel;
    
    [self.contentView addSubview:self.peopleLabel];
    
    
    UILabel * stopLabel = [UILabel new];
    
    stopLabel.textColor = [UIColor lightGrayColor];
    stopLabel.font = [UIFont systemFontOfSize:11 * SCREENH6];
    stopLabel.text = @"截止时间：2018-11-10";
    
    self.stopLabel = stopLabel;
    
    [self.contentView addSubview:self.stopLabel];
    
    
    UIButton * selecedButton = [UIButton new];
    
    [selecedButton setImage:[UIImage imageNamed:@"红色未勾选"] forState:UIControlStateNormal];
    [selecedButton setImage:[UIImage imageNamed:@"红色勾选"] forState:UIControlStateSelected];
    selecedButton.userInteractionEnabled = NO;
    
    self.selecedButton = selecedButton;
    
    [self.contentView addSubview:self.selecedButton];
}


- (void)layoutSubviews{
    
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.contentView);
        make.leading.mas_equalTo(self.contentView).offset(10 * SCREENH6);
    }];
    
    [self.peopleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.contentView);
        make.centerY.mas_equalTo(self.timeLabel);
    }];
    
    [self.stopLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.peopleLabel);
        make.top.mas_equalTo(self.peopleLabel.mas_bottom).offset(2 * SCREENH6);
    }];
    
    [self.selecedButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(self.contentView).offset(-10 * SCREENH6);
        make.centerY.mas_equalTo(self.contentView);
        make.height.width.mas_equalTo(20 * SCREENH6);
    }];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
